/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ITASwebservice;

import Entities.Pcroomlist;
import Entities.PcroomlistFacade;
import classes.Seat;
import java.util.ArrayList;
import java.util.List;
import javax.ejb.EJB;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.FormParam;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;

/**
 *
 * @author Sarah
 */
@Stateless
@Path("entities.pcroomlist")
public class PcroomlistFacadeREST extends AbstractFacade<Pcroomlist> {
    @EJB
    private PcroomlistFacade pcroomlistFacade;
    @PersistenceContext(unitName = "IServer-warPU")
    private EntityManager em;

    public PcroomlistFacadeREST() {
        super(Pcroomlist.class);
    }

    @POST
    @Override
    @Consumes({"application/xml", "application/json"})
    public void create(Pcroomlist entity) {
        super.create(entity);
    }

    @PUT
    @Override
    @Consumes({"application/xml", "application/json"})
    public void edit(Pcroomlist entity) {
        super.edit(entity);
    }

    @GET
    @Path("getPcroom")
    @Produces("application/json")
    public List<Pcroomlist> getPcroom() {
        return pcroomlistFacade.findAll();
    }
    
    @POST
    @Path("getSeats")
    @Consumes("application/json")
    @Produces("applacation/json")
    public Pcroomlist getSeats(String ID) {
        long pId = Long.parseLong(ID);
//        List<Pcroomlist> p = pcroomlistFacade.findAll();
//        for (int i=0; i<p.size(); i++) {
//            if (p.get(i).getId() == pId)
//                return p.get(i);
//        }
//        return null;
        return pcroomlistFacade.findAll().get(Integer.parseInt(pId+""));
    }
    
    @DELETE
    @Path("{id}")
    public void remove(@PathParam("id") Long id) {
        super.remove(super.find(id));
    }

    @GET
    @Path("{id}")
    @Produces({"application/xml", "application/json"})
    public Pcroomlist find(@PathParam("id") Long id) {
        return super.find(id);
    }

    @GET
    @Override
    @Produces({"application/xml", "application/json"})
    public List<Pcroomlist> findAll() {
        return super.findAll();
    }

    @GET
    @Path("{from}/{to}")
    @Produces({"application/xml", "application/json"})
    public List<Pcroomlist> findRange(@PathParam("from") Integer from, @PathParam("to") Integer to) {
        return super.findRange(new int[]{from, to});
    }

    @GET
    @Path("count")
    @Produces("text/plain")
    public String countREST() {
        return String.valueOf(super.count());
    }

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

}
